package mr.fileToDb;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author 李岩飞
 * @email eliyanfei@126.com
 * 2017年7月28日 上午9:41:58
 *
 */
public class SceneKpiBean implements Writable, DBWritable {
	public int time;
	public int sceneId;//居民区Id
	public int gridId;//栅格Id
	public int totalmrs;
	public float avgrsrp_v;
	public int avgrsrp_n;
	public boolean weakCoverage;//是否弱覆盖
	public int weakCoverageGrid;//弱覆盖栅格
	public int weakCoverageMR;//弱覆盖采样点
	public int validGrids;//弱覆盖采样点
	public int totalGrids;//弱覆盖采样点
	public int[] rsrp = new int[6];

	public String getKey() {
		return sceneId + "_" + gridId;
	}

	@Override
	public void readFields(ResultSet rs) throws SQLException {
		int idx = 1;
		sceneId = rs.getInt(idx++);
		time = rs.getInt(idx++);
		totalmrs = rs.getInt(idx++);
		avgrsrp_v = rs.getFloat(idx++);
		avgrsrp_n = rs.getInt(idx++);
		for (int i = 0; i < 6; i++) {
			rsrp[i] = rs.getInt(idx++);
		}
		weakCoverageGrid = rs.getInt(idx++);
		weakCoverageMR = rs.getInt(idx++);
		validGrids = rs.getInt(idx++);
		totalGrids = rs.getInt(idx++);
	}

	@Override
	public void write(PreparedStatement pst) throws SQLException {
		int idx = 1;
		pst.setInt(idx++, sceneId);
		pst.setInt(idx++, time);

		pst.setInt(idx++, totalmrs);
		pst.setFloat(idx++, avgrsrp_v);
		pst.setInt(idx++, avgrsrp_n);
		for (int i = 0; i < 6; i++) {
			pst.setInt(idx++, rsrp[i]);
		}
		pst.setInt(idx++, weakCoverageGrid);
		pst.setInt(idx++, weakCoverageMR);
		pst.setInt(idx++, validGrids);
		pst.setInt(idx++, totalGrids);
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		sceneId = in.readInt();
		gridId = in.readInt();
		time = in.readInt();
		totalmrs = in.readInt();
		avgrsrp_v = in.readFloat();
		avgrsrp_n = in.readInt();
		for (int i = 0; i < 6; i++) {
			rsrp[i] = in.readInt();
		}
		weakCoverage = in.readBoolean();
		weakCoverageMR = in.readInt();
	}

	@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(sceneId);
		out.writeInt(gridId);
		out.writeInt(time);
		out.writeInt(totalmrs);
		out.writeFloat(avgrsrp_v);
		out.writeInt(avgrsrp_n);
		for (int i = 0; i < 6; i++) {
			out.writeInt(rsrp[i]);
		}
		out.writeBoolean(weakCoverage);
		out.writeInt(weakCoverageMR);
	}
}
